package algorithm.view.prepare;

/**
 * @author bingo
 * @Description
 * @Date 2018/4/24
 */
public class Circle {

    /**x--->坐标*/
    public int x;
    /**y--->坐标*/
    public int y;

    /**圆的半径*/
    private int r;
    /**x方向速度**/
    public int vx;
    /**y方向速度*/
    public int vy;

    public Circle(int x, int y, int r, int vx, int vy) {
        this.x = x;
        this.y = y;
        this.r = r;
        this.vx = vx;
        this.vy = vy;
    }
   /**获取半径*/
    public int getR() {
        return r;
    }

    /**移动函数*/
    public void move(int minX,int maxX,int minY,int maxY){
        x += vx;
        y += vy;
        checkImpact(minX, maxX,minY, maxY);
    }
    /**碰撞检测*/
    public  void checkImpact(int minX,int maxX,int minY,int maxY){
        if(x-getR()<minX){
            x=r;
            vx =-vx;
        }
        if(x+getR()>=maxX){
            x  = maxX-r;
            vx = -vx;
        }
        if(y-getR()<minY){
            y=r;
            vy = -vy;
        }
        if(y+getR()>=maxY){
            y=maxY-r;
            vy = -vy;
        }

    }
}
